<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
	<link rel="stylesheet" href="__static/css/public.css" media="all">
	<style>
		.layui-form-pane .layui-form-label {
			width: 90px;
		}
	</style>
</head>
<body>
<div class="layuimini-container"> 
	<div class="layuimini-main">
		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<form class="layui-form layui-form-pane" action="">
				<div class="layui-form-item" style="margin-bottom: 5px;">
					<div class="layui-inline">
						<div class="layui-input-inline">
							<input type="text" name="order_num"  autocomplete="off" placeholder="请输入订单号" class="layui-input">
						</div>
						<div class="layui-input-inline">
							<input type="text" name="sell_time" id="date" autocomplete="off" placeholder="请选择销售时间" class="layui-input">
						</div>
						<div class="layui-input-inline">
							<select name="customer_id"  autocomplete="off" lay-search="">
								<option value="">请选择客户</option>
								{volist name="Customer_list" id='pt'}
									<option value="{$pt.id}" >{$pt.name}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<button type="button" class="layui-btn layui-btn-primary"  lay-submit="" lay-filter="search"><i class="layui-icon"></i> 搜 索</button>
					</div>
				</div>
			</form>
		</fieldset>
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-success layui-btn-sm data-add-btn" lay-event="add_order">添加订单</button>
			</div>
		</script>
		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
		<script type="text/html" id="currentTableBar">
			{{d.is_jiesuan < 2?'
				<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="save">修改</a>
				<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>':''}}
			
		</script>
		<script type="text/html" id="acc_list">
			<span onmouseover=get_msg(this) data-msg="{{d.reject}}" style="color: red;font-weight: bold;{{d.is_jiesuan == 1?'':'display:none;'}}">驳回</span>
			<span  style="color: #03A9F4;font-weight: bold;{{d.is_jiesuan == 0?'':'display:none;'}}">审核中</span>
			<span  style="color: #4CAF50;font-weight: bold;{{d.is_jiesuan == 2?'':'display:none;'}}">完成</span>
		</script>
	</div>
</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="__static/js/man.js" charset="utf-8"></script>
<script>
//添加订单
function add_order(){
	layer.open({
        type: 2,
        title:'添加订单',
        area: ['60%', '70%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('add_order')}"
    });
    //layer.full(index);
}
//修改订单
function get_save_order(id){
	layer.open({
        type: 2,
        title:'修改订单',
        area: ['60%', '70%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('save_order')}?id="+id
    });
    //layer.full(index);
}
	var $,form,table,laydate
	layui.use(['form', 'table', 'tableSelect', 'laydate'], function () {
		$ = layui.jquery , form = layui.form , table = layui.table , laydate = layui.laydate
		 laydate.render({
			    elem: '#date', //指定元素
			  });
		//监听搜索提交
		  form.on('submit(search)', function(data){
			var articleFrom = data.field;
			table.reload('items_list', {
				  url: '{:url("index")}?t=json',
				  where:articleFrom
				});
			return false;
		  });
		table.render({
			elem: '#currentTableId',
			id:'items_list',
			url: '{:url("index")}?t=json',
			height: 'full-150',
			method : 'post',
			toolbar: '#toolbarDemo',
			cols: [[
				{ field: 'order_num', title: '订单号',width:"180"},
				{ field: 'sell', title: '销售单价',width:"100"},
				{ field: 'num', title: '销售数量',width:"100"},
				{ field: 'total', title: '销售总价',width:"120"},
				{ field: 'rebates', title: '销售点',width:"100" , templet: function (d) {
                    return d.rebates+"%"
            	}},
				{ field: 'type', title: '类型',width:80 , templet: function (d) {
                    return d.type ==1?"表单":"视频" 
            	}},
				{ field: 'customer_name', title: '客户名称' ,width:"120", },
				{ field: 'pinzheng', title: '凭证',width:120 , templet: function (d) {
                    return d.pinzheng ?"<img src='"+d.pinzheng+"'>":"" 
            	}},
            	{ field: 'is_jiesuan', title: '状态',width:80 , templet:'#acc_list'},
			    { field: 'note', title: '备注',width:"200"},
			    { field: 'media_name', title: '媒介',width:"120"},
			    { field: 'sell_time', title: '销售时间',width:"180", templet: function (d) {
                    return date("Y-m-d",d.sell_time) 
            	}},
			    { title: '操作', minWidth: 150, fixed: 'right', toolbar: '#currentTableBar',align:'center'}
			]],
			limit: 30,
			page: true,
			skin: 'line'
		});
		 
		/**
		 * toolbar监听事件
		 */
		table.on('toolbar(currentTableFilter)', function (obj) {
			switch (obj.event) {
				case 'add_order':
					add_order();
				break;
			}
			
		});
		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'save':
					get_save_order(data.id);
				break;
				case 'delete':
					layer.confirm('您确认要删除此订单吗？', {
		                btn: ['确认', '取消'] //按钮
		            }, function () {
		            	layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
						$.post("{:url('del_order')}?t=json",{id:data.id},function(da){
							layer.closeAll();
							if(da['code'] == 1){
								obj.del(); 
								layer.msg(da['msg'], {icon: 6});
							}else{
							 layer.msg(da['msg'], { icon : 5 });
							}
						});
		            });
					
					
				break;
			}
		});
		//监听行单击事件
		table.on('row(currentTableFilter)', function(obj){
			layer.photos({
				  photos: obj.tr
				  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
				});
		});

	});
	function get_load(msg){
		table.reload('items_list', {
			  url: '{:url("index")}?t=json',
			});
		layer.msg(msg, {icon: 6});
	}
	function get_seek(){
		var name = $("input[name=item]").val();
		table.reload('items_list', {
			  url: '{:url("index")}?t=json',
			  where:{name:name}
			});
	}
	//显示驳回信息
	function get_msg(obj){
		var str = $(obj).attr('data-msg');
		layer.tips(str,obj);
	}
</script>

</body>
</html>